<template>
    <i-table size="small" :columns="columns1" :data="data"></i-table>
</template>
<script>
    module.exports = {
        props: {
            columns: Array,
            data: Array,
        },
        data(){
            columns1:[]
        },
        methods: {
            update(data){
                this.$emit('itabeupdate',data)
            },
        },
        computed: {
            columns1() {
                let c = []
                c.push({
                    title: '#',
                    align: 'center',
                    type: 'expand',
                    width: 50,
                    render: (h, params) => {
                        if (params.row.child) {
                            return h('itable-body', {
                                props: {
                                    columns: this.columns,
                                    data: params.row.children,
                                    parent:this.data[params.index]
                                },
                                on:{
                                    itabeupdate:(data)=>{
                                        this.$emit('itabeupdate',data)
                                    }
                                }
                            });
                        } else {
                            return h('');
                        }

                    }
                })
              if(this.columns){
                  this.columns.forEach(col => {
                      c.push(col)
                      // console.log(c);
                  })
              }

                c.push({
                    title: '操作',
                    key: 'action',
                    align: 'center',
                    render: (h, params) => {
                        let btns = [];
                        btns.push(
                            h('Button', {
                                props: {
                                    type: 'info',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '8px'
                                },
                                on: {
                                    click: () => {
                                        console.info(this)
                                        this.$emit('itabeupdate',this.data[params.index])
                                    }
                                }
                            }, '修改')
                        )

                        btns.push(
                            h('Button', {
                                props: {
                                    type: 'info',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '8px'
                                },
                                on: {
                                    click: () => {
                                        console.info("del")
                                        this.$emit('itabeupdate',this.data[params.index])
                                    }
                                }
                            }, '删除')
                        )

                        return h('div', btns);
                    }
                })

                console.log(c,this.data);
                return c
            }
        }
    }
</script>
